import store from '../redux/store.js';
import React, { useEffect } from 'react';
export default function Count() {
  const count= store.getState();

  // componentDidMount = () => {
  //   store.subscribe(() => {
  //     // this.render();
  //     this.setState({});
  //   })
  // }
  // console.log('count', count);
  useEffect(() => {
    console.log('组件挂载完成，类似于componentDidMount');
    this.setState({});
  }, []);

  const add = (e) => {
    console.log('count', count);
    store.dispatch({ type: 'add', data: e.detail*1 })
  }
  

  return (
    <div>
      <h2>当前求和为：{count}</h2>
      <button onClick={add}> +1 </button>
      <button onClick={e => store.dispatch({ type: 'minus' })}> -1 </button>
    </div>
  )
}